﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cadbom
{
    public partial class SemiProductForm : Form
    {
        Action<string> callback = null;
        public SemiProductForm(Action<string> callback)
        {
            InitializeComponent();
            this.button1.Visible = false;
            this.button2.Visible = false;
            this.callback = callback;
            this.button3.Visible = false;
        }

        private void SemiProductForm_Load(object sender, EventArgs e)
        {

        }
        public void InitFormFields(BasProductImport product,string action,List<string> checkResults)
        {
            this.textBox1.Text = product.code;
            this.textBox2.Text = product.name;
            this.textBox3.Text = product.model;
            this.textBox4.Text = product.drawingNo;
            this.textBox5.Text = product.description;
            this.textBox6.Text = product.productVer;
            this.textBox7.Text = product.mainCompDesc;
            this.textBox8.Text = product.materialThickness;
            this.textBox9.Text = product.sizeLength;
            this.textBox10.Text = product.sizeWidth;
            this.textBox11.Text = product.weight;
            this.textBox12.Text = product.faceProcess;
            this.textBox13.Text = product.customerCode;
            if (action == "edit")
            {
                this.button1.Visible = false;
                this.button2.Visible = true;
                this.button3.Visible = true;
                this.label14.Text = "注：ERP编码系统已经存在，是否要编辑？";
            }
            else
            {
                this.button3.Visible = false;
                this.button1.Visible = true;
                this.button2.Visible = false;
                this.label14.Text = "注：ERP编码系统不存在，是否要新建？";
            }
            if (checkResults.Count > 0)
            {
                checkResults.ForEach(t=>{
                    this.richTextBox1.AppendText(t + "\r\n");
                });
                
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            callback.Invoke("edit");
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            callback.Invoke("save");
            this.Close();
        }

        private void SemiProductForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            callback.Invoke("close");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            callback.Invoke("cancel");
            this.Close();
        }
    }
}
